package com.ruitu.mall_98_2.mvp.presenter;

import com.beanu.arad.utils.Logg;
import com.beanu.arad.utils.ToastUtils;
import com.ruitu.mall_98_2.mvp.contract.OrderContract;
import com.ruitu.router_module.bean.api.BaseResult;
import com.ruitu.router_module.bean.api.PageModel;
import com.ruitu.router_module.bean.api.SubscriberImpl;
import com.ruitu.router_module.bean.order.Order;
import com.ruitu.router_module.bean.order.SmallOrder;

public class OrderPresenter extends OrderContract.Presenter {
    @Override
    public void getOtherAllOrders(String accountId, String status, String page, String size) {
        mModel.getOtherAllOrders(accountId, status, page, size)
                .subscribe(new SubscriberImpl<BaseResult<PageModel<SmallOrder>>>() {
                    @Override
                    public void onError(Throwable e) {
                        mView.hideProgress();
                        Logg.i(e.toString());
                        mView.setFail();
                        ToastUtils.showShort("获取订单失败");
                    }

                    @Override
                    public void onNext(BaseResult<PageModel<SmallOrder>> pageModelBaseResult) {
                        mView.hideProgress();
                        if (pageModelBaseResult.isSuccess()) {
                            mView.setData1(pageModelBaseResult.getData());
                        }
                    }
                });
    }

    @Override
    public void orderInfo(String accountId) {
        mModel.orderInfo(accountId)
                .subscribe(new SubscriberImpl<BaseResult<Order>>() {
                    @Override
                    public void onError(Throwable e) {
                        mView.hideProgress();
                        Logg.i(e.toString());
                        mView.setFail();
                        ToastUtils.showShort("获取订单失败");
                    }

                    @Override
                    public void onNext(BaseResult<Order> listBaseResult) {
                        mView.hideProgress();
                        if (listBaseResult.isSuccess()) {
                            mView.setData(listBaseResult.getData());
                        } else {
                            ToastUtils.showShort(listBaseResult.getMsg());
                        }
                    }
                });
    }

    @Override
    public void deleteOrder(String orderId) {
        mModel.deleteOrder(orderId)
                .subscribe(new SubscriberImpl<BaseResult>() {
                    @Override
                    public void onError(Throwable e) {
                        mView.hideProgress();
                        ToastUtils.showShort("删除订单失败");
                    }

                    @Override
                    public void onNext(BaseResult baseResult) {
                        mView.hideProgress();
                        if (baseResult.isSuccess()) {
                            mView.setSuc();
                        }else {
                            ToastUtils.showShort(baseResult.getMsg());
                        }
                    }
                });
    }

    @Override
    public void qrsh(String odId) {
        mModel.qrsh(odId)
                .subscribe(new SubscriberImpl<BaseResult>() {
                    @Override
                    public void onError(Throwable e) {
                        mView.hideProgress();
                        ToastUtils.showShort("确认收货失败");
                    }

                    @Override
                    public void onNext(BaseResult baseResult) {
                        mView.hideProgress();
                        if (baseResult.isSuccess()) {
                            mView.setSuc();
                        } else {
                            ToastUtils.showShort(baseResult.getMsg());
                        }
                    }
                });
    }

    @Override
    public void cancelOrder(String orderId) {
        mModel.cancelOrder(orderId)
                .subscribe(new SubscriberImpl<BaseResult>() {
                    @Override
                    public void onError(Throwable e) {
                        mView.hideProgress();
                        ToastUtils.showShort("取消订单失败");
                    }

                    @Override
                    public void onNext(BaseResult baseResult) {
                        mView.hideProgress();
                        if (baseResult.isSuccess()) {
                            mView.setSuc();
                        } else {
                            ToastUtils.showShort(baseResult.getMsg());
                        }

                    }
                });
    }

    @Override
    public void getOrderTracesByJson(String odId) {
        mModel.getOrderTracesByJson(odId)
                .subscribe(new SubscriberImpl<BaseResult>() {
                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onNext(BaseResult baseResult) {

                    }
                });
    }
}
